<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu($this->parameter("menu"))?>


    <h1><?=$this->message("label.category.header", $this->parameter("bundle"))?></h1>


    <? /* Breadcrums route & page info display */ ?>
    <?=$this->route(
        $this->message("label.category.header", $this->parameter("bundle")),
        $this->categoryListForm,                                  // ListForm (for page info, see float right)
        $this->categories($this->categoryListForm)->getRows() // The total amount of categorys
    )?>


    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->categoryListForm)?>"
          name="<?=get_class($this->categoryListForm)?>"
          method="post"
          action="<?=$this->parameter("module")?>/category/list"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            $this->parameter("module")."/category/edit", // Add New URL
            $this->categoryListForm,                     // ListForm
            array(                                       // Filter fields
                CategoryI18nPeer::NAME=>$this->message("category.name", _Core::BUNDLE),
                CategoryI18nPeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                CategoryI18nPeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE),
                CategoryI18nPeer::ACTIVE=>$this->message("choose.active", _Core::BUNDLE)
            )
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table cellspacing="0" cellpadding="0" class="list">
        <tr>
            <th class="checkbox"></th>
            <th class="narrow"></th>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language", _Core::BUNDLE)?>">
                    <?=$this->message("label.language", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th>
                <?=$this->TH(
                    $this->categoryListForm,                                 // ListForm
                    CategoryI18nPeer::NAME,                           // Sort Field
                    $this->message("category.name", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->categoryListForm,                        // ListForm
                    "count",                                        // Sort Field
                    $this->message("label.category.items", $this->parameter("bundle")) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->categoryListForm,                           // ListForm
                    CategoryI18nPeer::MODIFIED_DATE,            // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->categoryListForm,                          // ListForm
                    CategoryI18nPeer::INSERT_DATE,             // Sort Field
                    $this->message("choose.created", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow" title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->categoryListForm,                        // ListForm
                    CategoryI18nPeer::ACTIVE,                // Sort Field
                    $this->message("label.active", _Core::BUNDLE) // Header Name
                )?>
            </th>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">
                    <?=$this->message("label.language.available", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th class="buttons"></th>
        </tr>

        <? foreach($this->categories($this->categoryListForm)->getItems() as $categoryI18n): ?>

            <tr class="ctrl">
                <td class="checkbox">
                    <input type="checkbox"
                           name="items[]"
                           value="<?=$categoryI18n->getCategoryI18nId()?>"
                           <?=in_array($categoryI18n->getCategoryI18nId(), $this->categoryListForm->getItems()) ? " checked=\"checked\"" : ""?> />
                </td>
                <td>
                    <? if($categoryI18n->getCategory()->getImageId() > 0): ?>
                    <a title="<?=$this->message("title.image", _Core::BUNDLE)?>" href="image?id=<?=$categoryI18n->getCategory()->getImageId()?>">
                        <?=$this->thumbnail($categoryI18n->getCategory()->getThumbnailId())?>
                    </a>
                    <? endif; ?>
                </td>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($categoryI18n->getLanguage()->getCode()).".png")?>"
                             width="16" height="11" alt="<?=$categoryI18n->getLanguage()->getName()?>"
                             title="<?=$categoryI18n->getLanguage()->getName()?>" />

                    </td>
                <? endif; ?>
                
                <td><?=$categoryI18n->getName()?></td>
                <td title="<?=$this->message("title.category.items", $this->parameter("bundle"))?>">
                    <a title="<?=$this->message("title.category.items", $this->parameter("bundle"))?>" href="<?=$this->parameter("module")?>/list?id=<?=$categoryI18n->getCategoryId()?>">
                        <?=$categoryI18n->getCount()?>
                    </a>
                </td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$categoryI18n->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$categoryI18n->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$categoryI18n->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$categoryI18n->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($categoryI18n->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                </td>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">

                        <? /* Only show available languages when item language same as CMS default language) */ ?>
                        <? if($categoryI18n->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)) { ?>
                            <? foreach($categoryI18n->getAvailableLanguages() as $language) { ?>
                                <a href="<?=$this->parameter("module")?>/category/edit?categoryI18n->categoryId=<?=$categoryI18n->getCategoryId()?>&amp;categoryI18n->languageCode=<?=$language->getCode()?>">
                                    <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($language->getCode()).".png")?>"
                                         width="16" height="11"
                                         alt="<?=$language->getName()?>"
                                         title="<?=$this->message("title.translate.item", _Core::BUNDLE)?> (<?=$language->getName()?>)."
                                         class="flag" />
                                 </a>
                            <? } ?>
                        <? } ?>

                    </td>
                <? endif; ?>
               
                <td class="buttons">

                    <input type="button"
                           onclick="to('<?=$this->parameter("module")?>/category/edit?categoryI18n->categoryI18nId=<?=$categoryI18n->getCategoryI18nId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />
                    <input type="button"
                           onclick="del(<?=$categoryI18n->getCategoryI18nId()?>, '<?=get_class($this->categoryListForm)?>')"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

            <? /* Loop through the foreign languages when i18n enabled & language selectbox is on ALL */?>
            <? if($this->param(_Core::I18N) && strlen($this->categoryListForm->getLanguage()) == 0 && strlen($this->categoryListForm->getQuery()) == 0): ?>

                <? foreach($categoryI18n->getForeignCategory18ns(
                    $this->param(_Core::DEFAULT_LANGUAGE),
                    CategoryI18nPeer::NAME,
                    $this->categoryListForm->getDirection()) as $i18nCategory): ?>

                <tr class="ctrlsub">
                    <td class="checkbox">

                        <input type="checkbox"
                           name="categorys[]"
                           value="<?=$i18nCategory->getCategoryI18nId()?>"
                           <?=in_array($i18nCategory->getCategoryI18nId(), $this->categoryListForm->getItems()) ? " checked=\"checked\"" : ""?> />

                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($i18nCategory->getLanguage()->getCode()).".png")?>"
                             width="16" height="11"
                             alt="<?=$i18nCategory->getLanguage()->getName()?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nCategory->getLanguage()->getName()?>)" />

                    </td>
                    <td>

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_merge.png")?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nCategory->getLanguage()->getName()?>)"
                             width="16" height="16" alt="" />
                        <?=$i18nCategory->getName()?>

                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$i18nCategory->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nCategory->getModifiedDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$i18nCategory->getInsertDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nCategory->getInsertDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                        <?=$this->message("label." . ($i18nCategory->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                    </td>

                    <? /* Only show move arrows & available languages when language selectbox is on ALL) */ ?>
                    <? if(strlen($this->categoryListForm->getLanguage()) == 0 && strlen($this->categoryListForm->getQuery()) == 0): ?>
                        <td></td>
                    <? endif; ?>

                    <td class="buttons">

                        <input type="button"
                               onclick="to('<?=$this->parameter("module")?>/category/edit?categoryI18n->categoryI18nId=<?=$i18nCategory->getCategoryI18nId()?>')"
                               class="button"
                               value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                        <input type="button"
                               onclick="del(<?=$i18nCategory->getCategoryI18nId()?>, '<?=get_class($this->categoryListForm)?>')"
                               class="button"
                               value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                    </td>
                </tr>
                <? endforeach; ?>

            <? endif; ?>

        <? endforeach; ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->categoryListForm, // ListForm
            array(               // The actions
                "activate"=>$this->message("choose.activate", _Core::BUNDLE),
                "deactivate"=>$this->message("choose.deactivate", _Core::BUNDLE),
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->categoryListForm,
            $this->parameter("module")."/category/edit",
            $this->categories($this->categoryListForm)->getRows()
        )?>


    </form>

<?=$this->footer()?>